package com.gfhd.multithread.threadpool;

import java.util.concurrent.*;

public class ThreadPoolDemo1 {
    public void test() {
        ExecutorService pool = new ThreadPoolExecutor(3,
                5,
                6,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(5),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        Runnable target = new MyRunnable();
        pool.execute(target);
        pool.execute(target);
        pool.execute(target);
        pool.execute(target);
        pool.execute(target);

        Future<Integer> f1=pool.submit(new MyCallable(100));
        Future<Integer> f2=pool.submit(new MyCallable(200));
        Future<Integer> f3=pool.submit(new MyCallable(300));
        Future<Integer> f4=pool.submit(new MyCallable(400));
        Future<Integer> f5=pool.submit(new MyCallable(400));
        try {
            System.out.println(f1.get());
            System.out.println(f2.get());
            System.out.println(f3.get());
            System.out.println(f4.get());
            System.out.println(f5.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

    }
}
